import requests
from openpyxl import Workbook
from bs4 import  BeautifulSoup
from pyecharts.charts import Line
from pyecharts.charts import Bar
from pyecharts.charts import Pie
nos=[]
title=["电影榜单","电视剧","动漫",'综艺']
host=[]
name=[]
url="http://w3ic.com/"
#header={"User-Agent":" Mozilla/5.0"}
re = requests.get ( url)
#print(re.text)
soup=BeautifulSoup(re.text,"html.parser")
for li in soup.findAll(name="li",attrs={"class":"bang_1"}):
    nos.append(li.contents[1].string)
    host.append(li.contents[3].string)
    name.append(li.contents[5].string)
wb = Workbook()
ws1=wb.create_sheet(title[0],0)
ws2=wb.create_sheet(title[1],1)
ws3=wb.create_sheet(title[2],2)
ws4=wb.create_sheet(title[3],3)
ws = wb.active
rows=[]
ws1.append(["排名","热度","名称"])
ws2.append(["排名","热度","名称"])
ws3.append(["排名","热度","名称"])
ws4.append(["排名","热度","名称"])
for r in range(len(nos)):
    if r>=0 and r<12:
        ws1.append([nos[r],host[r],name[r]])
    if r >= 12 and r < 24:
        ws2.append([nos[r], host[r], name[r]])
    if r >=24 and r < 36:
        ws3.append([nos[r], host[r], name[r]])
    if r >=36 and r < 48:
        ws4.append([nos[r], host[r], name[r]])
wb.save("all排行榜.xlsx")
print(name)
print(nos)
print(host)
from openpyxl import load_workbook
wb = load_workbook("all排行榜.xlsx")
ws1 = wb.active
for row in ws1.iter_rows():
    for cell in row:
        print(cell.value,end="  ")
    print()
print()
ws2 = wb.active
for row in ws2.iter_rows():
    for cell in row:
        print(cell.value,end="  ")
    print()
print()
ws3 = wb.active
for row in ws3.iter_rows():
    for cell in row:
        print(cell.value,end="  ")
    print()
print()
ws4 = wb.active
for row in ws4.iter_rows():
    for cell in row:
        print(cell.value,end="  ")
    print()
print()
bar=Bar()
bar.add_xaxis(name)
bar.add_yaxis("排名",nos[0:12])
bar.add_yaxis("热点",host[0:12])
bar.render("movie1.html")

bar1=Bar()
bar1.add_xaxis(name)
bar1.add_yaxis("排名",nos[12:24])
bar1.add_yaxis("热点",host[12:24])
bar1.render("movie2.html")

line=Line()
line.add_xaxis(name)
line.add_yaxis("排名",nos[0:12])
line.add_yaxis("热点",host[0:12])
line.render("movie1-折线.html")
